﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Login</title>
    <link href="~/lib/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />
    <link href="~/font/bootstrap-icons.css" rel="stylesheet" />
    <link href="~/css/site.css" rel="stylesheet" />
    <link href="~/css/login.css" rel="stylesheet" />

</head>

<body class="text-center">
    <main class="form-signin w-100 m-auto">
        <form>
            <img class="mb-4" src="~/img/favicon.ico" alt="" width="72" height="57">
            <h1 class="h3 mb-3 fw-normal">欢迎使用</h1>

            <div class="form-floating">
                <input type="text" class="form-control" id="userName" placeholder="用户名">
                <label for="Account">用户名</label>
            </div>
            
            <div class="form-floating">
                <input type="password" class="form-control" id="password" placeholder="密码">
                <label for="password">密码</label>
            </div>

            
            <button id="loginBtn" class="w-100 btn btn-lg btn-primary" type="button">登录</button>
            <p class="mt-5 mb-3 text-muted">&copy; 2017–2023</p>
        </form>
    </main>
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
    <script>
        $('#loginBtn').click(function(){
            let userName=$('#userName').val()
            let password=$('#password').val()
            if (userName == "" || password == "")
                return false

            let user = { UserName: userName, Password: password }
            $.ajax({
                url:'/Login/Login',
                type:'post',
                data:user,
                success:function(data){
                    sessionStorage.setItem('user',JSON.stringify(data))
                    if(data!=null)
                    {
                        //页面跳转
                        location.href='/Home/Index'
                    }
                    else{
                        alert('用户名或密码错误!')
                    }
                },
                error:function(){
                    
                }
            })
        })
    </script>
</body>
</html>
